//
//  Folder.swift
//  hello
//
//  Created by 赵康 on 2025/4/15.
//
import Vapor
import Fluent

// 收藏夹模型
final class Folder: Model, Content, @unchecked Sendable {
	static var schema: String { SchemaEnum.folders.rawValue }
	
	@ID(key: .id)
	var id: UUID?
	
	@Field(key: FieldKeys.name)
	var name: String
	
	@Field(key: FieldKeys.isDefault)
	var isDefault: Bool
	
	@Parent(key: FieldKeys.user)
	var user: User
	
	@Children(for: \.$folder)
	var favorites: [Favorite]
	
	@Field(key: FieldKeys.position)
	var position: Int
	
	@Timestamp(key: FieldKeys.createdAt, on: .create)
	var createdAt: Date?
	
	@Timestamp(key: FieldKeys.updatedAt, on: .update)
	var updatedAt: Date?
	
	init() { }
	
	init(id: UUID? = nil, name: String, isDefault: Bool, userID: User.IDValue, position: Int = 0, createdAt: Date? = Date(), updatedAt: Date? = Date()) {
		self.id = id
		self.name = name
		self.isDefault = isDefault
		self.$user.id = userID
		self.position = position
		self.createdAt = createdAt
		self.updatedAt = updatedAt
	}
}


  // 收藏夹响应模型
struct FolderResponse: Content {
  let id: UUID
  let name: String
  let isDefault: Bool
  let createdAt: Date?
  let albumCount: Int
}

  // 创建收藏夹请求模型
struct CreateFolderRequest: Content {
  let name: String
  let isDefault: Bool?
}

  // 重命名收藏夹请求模型
struct RenameFolderRequest: Content {
  let name: String
}

  // 添加到收藏夹请求模型
struct AddToFolderRequest: Content {
  let albumID: UUID
  let folderID: UUID
}

  // 更新收藏夹顺序请求模型
struct UpdateFoldersOrderRequest: Content {
  let folderOrders: [FolderOrderItem]
}

struct FolderOrderItem: Content {
  let id: UUID
  let position: Int
}
